package q763;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * 763. 划分字母区间
 */
public class Solution {

    public List<Integer> partitionLabels(String s) {
        Set<Character> used = new HashSet<>();
        List<Integer> res = new ArrayList<>();
        int l = 0;
        for (int i = 0; i < s.length(); i++) {
            used.add(s.charAt(i));
            boolean found = false;
            for (int j = i + 1; j < s.length(); j++) {
                if (used.contains(s.charAt(j))) {
                    found = true;
                    break;
                }
            }
            if (!found) {
                used.clear();
                res.add(i - l + 1);
                l = i + 1;
            }
        }
        return res;
    }

    public static void main(String[] args) {
        Solution solution = new Solution();
        String s = "ababcbacadefegdehijhklij";
//        String s = "eccbbbbdec";
        System.out.println(solution.partitionLabels(s));
    }
}
